<style lang="scss" scoped>
@import url(./mywallet.scss);
</style>
<template>
  <div class="mywalletBox">
    <div class="top">
      <van-nav-bar title="我的钱包" right-text="查看绑定" left-arrow @click-left="$router.push('/my')"
        @click-right="$router.push('/bindcard')" />
    </div>
    <div class="con">
      <div class="HBbox">
        <p class="p1">我的H币</p>
        <h1>{{ list.balance }}</h1>
        <p class="p2">(满20000可提现)</p>
        <van-button type="primary" size="small" @click="$router.push('/withdrawalpage')">提现</van-button>
      </div>
      <div class="footer">
        <dl style="height: 40px" v-for="(item, i) in datalist" :key="i">
          <dt>{{ item.incomeType }}</dt>
          <dd>
            <span style="color: #999; font-size: 12px">{{
              dayjs(item.recordTime).format('YYYY-MM-DD')
            }}</span>
            <span style="color: red; font-size: 16px; margin-top: -20px">{{ item.incomeType == '提现' ? '-' : '+' }}{{
              item.money }}H币</span>
          </dd>
        </dl>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, reactive } from 'vue'
// import { usecurrentStore } from '../../stores/mony'
import { getFindDoctorWallet, getFindDoctorIncomeRecordList } from '@/api/wallet'
import { closeNotify, showNotify } from 'vant'
import { useRouter } from 'vue-router'
import dayjs from 'dayjs'

const router = useRouter()
const result = localStorage.getItem('result')
const doctorId = JSON.parse(localStorage.getItem('doctorId') as string)
const sessionId = JSON.parse(localStorage.getItem('sessionId') as string)

// hb币余额
const list: any = ref([])
getFindDoctorWallet(doctorId, sessionId).then(res => {
  console.log(res);
  list.value = res.data.result
})

const page = ref(1)
const count = ref(10)

const config = reactive({
  page: page.value,
  count: count.value
})
//查询医生收支记录
const datalist:any = ref([])
getFindDoctorIncomeRecordList(doctorId, sessionId, config).then(res => {
  datalist.value = res.data.result
  console.log(res);
})

getFindDoctorIncomeRecordList(doctorId, sessionId, config).then(res => {
  res.data.result.forEach((item: any) => {
    switch (item.incomeType) {
      case 1:
        item.incomeType = '问诊';
        break;
      case 2:
        item.incomeType = '采纳建议';
        break;
      case 3:
        item.incomeType = '收礼物';
        break;
      case 4:
        item.incomeType = '提现';
        break;
    }
  });
  datalist.value = res.data.result;
  console.log(res);
})
// onMounted(async () => {
//   const page = 1
//   const count = 10
//   //查询医生钱包
//   await store.handmony(doctorId, sessionId)
//   // 查询医生收支记录
//   await store.DoctorIncomeRecordList(doctorId, sessionId, page, count)
//   // 获取收支流水明细
//   store.incomerecordlist.forEach((item: any) => {
//     switch (item.incomeType) {
//       case 1:
//         item.incomeType = '问诊'
//         break
//       case 2:
//         item.incomeType = '采纳建议'
//         break
//       case 3:
//         item.incomeType = '收礼物'
//         break
//       case 4:
//         item.incomeType = '提现'
//         break
//     }
//     store.incomerecordlist.incomeType = item.incomeType
//   })
// })
// 判断
const someAsyncFunction = () => {
  try {
    // const result = await somePromise();
    if (result) {
      console.log('已登录')
      setTimeout(closeNotify, 3000) // 3 秒后关闭通知
    } else {
      console.log('未登录')
      router.push('/login')
      setTimeout(closeNotify, 3000) // 3 秒后关闭通知
    }
  } catch (error: any) {
    showNotify({ type: 'danger', message: '发生错误：' + error.message })
    setTimeout(closeNotify, 3000) // 3 秒后关闭通知
  }
}
someAsyncFunction()
</script>